Skip to content

Conversation

@MartinSarkany
Copy link
Contributor

@MartinSarkany MartinSarkany commented Sep 24, 2025

Pull Request Template

Description

Adds synchronous initialization to CosmosDataEncryptionKeyProvider.
Depends on #5418 due to TestEncryptionKeyStoreProvider being introduced there.

Type of change

Please delete options that are not relevant.

  • [] New feature (non-breaking change which adds functionality)

Closing issues

closes #5400

@MartinSarkany MartinSarkany marked this pull request as ready for review September 24, 2025 15:41
@MartinSarkany MartinSarkany changed the title Add synchronous initialization to CosmosDataEncryptionKeyProvider [Client encryption] Add synchronous initialization to CosmosDataEncryptionKeyProvider Sep 24, 2025
Copy link
Contributor

@juraj-blazek juraj-blazek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to regenerate public API contracts, too

@MartinSarkany
Copy link
Contributor Author

We need to regenerate public API contracts, too

I'll update it after #5373 that fixes the contracts is merged. It is broken at the moment.

@adamnova
Copy link
Contributor

We need to regenerate public API contracts, too

I'll update it after #5373 that fixes the contracts is merged. It is broken at the moment.

But it should work for .net 6 at least.

/// Initialize using an existing Cosmos DB container for storing wrapped DEKs.
/// </summary>
/// <param name="container">Existing Cosmos DB container.</param>
public void Initialize(Container container)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are assumptions about the partition-key which were validated in initialization
Its even high impactful post initialization if CosmosDB is unavailable right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to XML doc.

}

/// <summary>
/// Initialize using an existing Cosmos DB container for storing wrapped DEKs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include the container requirements (ex: partitionKeyDefinition)
And also call out right usage pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extended the XML doc with these details.

{
this.ThrowIfAlreadyInitialized();

this.container = container ?? throw new ArgumentNullException(nameof(container));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on handling non-existing containers on Fetch* API's? (i.e. on failure attempt re-create it)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concurrency control is also an important aspect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the race condition.

However, I'm not sure about container re-creation as the container should exist after successful initialization and we probably can't re-create the same container if it's initialized using the Initialize() method. The caller has an option to react to failure by providing a new Container or using InitializeAsync() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Client encryption]: Initialize CosmosDataEncryptionKeyProvider without making a backend call

4 participants